import * as Blockly from 'blockly/core';
import { Msg } from 'blockly/core';
import { BLOCK_HUE } from './config';

export const mixly_lib_fs_convert = {
    init: function () {
        this.appendValueInput('DATA');
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(BLOCK_HUE);
        this.setTooltip('');
        this.setHelpUrl('');
    }
};

export const mixly_lib_fs_dir_pointer = {
    init: function () {
        this.appendValueInput('DIR')
            .setCheck(null)
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(Msg.MIXLY_LIB_FS_DIR_POINTER)
            .appendField(new Blockly.FieldTextInput('dir'), 'VAR')
            .appendField(Msg.MIXLY_VALUE);
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(BLOCK_HUE);
        this.setTooltip('');
        this.setHelpUrl('');
    },
    getVars: function () {
        return [this.getFieldValue('VAR')];
    },
    renameVar: function (oldName, newName) {
        if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
            this.setFieldValue(newName, 'VAR');
        }
    }
};

export const mixly_lib_fs_file_pointer = {
    init: function () {
        this.appendValueInput('FILE')
            .setCheck(null)
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField(Msg.MIXLY_LIB_FS_FILE_POINTER)
            .appendField(new Blockly.FieldTextInput('file'), 'VAR')
            .appendField(Msg.MIXLY_VALUE);
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(BLOCK_HUE);
        this.setTooltip('');
        this.setHelpUrl('');
    },
    getVars: function () {
        return [this.getFieldValue('VAR')];
    },
    renameVar: function (oldName, newName) {
        if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
            this.setFieldValue(newName, 'VAR');
        }
    }
};